Skip to content

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Feb 19, 2025

Description

In this PR, I have fixed a mutation issue on command modal actions. This issue was observer when we were updating the work item detail from the command modal, the properties of the work item was updated but the command modal still showed stale data.

To Fix this issue, I have update the component to use data from mobx store instead of relying on the initial SWR call.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

  • Before
Screen.Recording.2025-02-19.at.2.27.21.PM.mov
  • After
Screen.Recording.2025-02-19.at.2.26.44.PM.mov

Summary by CodeRabbit

  • Refactor
    • Improved the command interface’s data retrieval process for issue details, ensuring more reliable and consistent display of information.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The CommandModal component in the command-modal.tsx file has been updated to enhance the handling of issue details. The useIssueDetail hook is now destructured to include a new getIssueById function. This function is used to derive issue details from the workItemDetailsSWR data rather than using a direct assignment. Additionally, the variable naming has been revised along with a clarifying comment, making the data-fetching logic more explicit and structured.

Changes

File Summary
web/core/.../command-modal.tsx Expanded destructuring from useIssueDetail to include getIssueById. Refactored the assignment of issue details to derive them via getIssueById from workItemDetailsSWR, including renaming for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant CM as CommandModal
    participant Hook as useIssueDetail
    participant SWR as workItemDetailsSWR

    CM->>Hook: Call useIssueDetail()
    Hook-->>CM: Return { issue: { getIssueById }, fetchIssueWithIdentifier }
    CM->>Hook: Call getIssueById(issueId)
    Hook-->>CM: Return issue details
    Note over CM: Issue details derived from SWR via getIssueById
Loading

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend

Suggested reviewers

  • sriramveeraghanta

Poem

I hopped into the code with a skip and a cheer,
Spotting bugs that I held dear.
With getIssueById tucked in my paw,
CommandModal now runs without flaw.
Carrots and code, a delightful spree—
Watch our issues dance merrily! 🥕💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
web/core/components/command-palette/command-modal.tsx (1)

336-339: Consider adding loading state for issue details.

While the implementation correctly uses the store data, it might be good to add a loading state when the issue details are being fetched to improve the user experience.

 {issueId && issueDetails && searchInIssue && (
+  <>
+    {!issueDetails ? (
+      <div className="flex items-center justify-center p-4">
+        <Loader className="w-5 h-5" />
+      </div>
+    ) : (
       <CommandPaletteIssueActions
         closePalette={closePalette}
         issueDetails={issueDetails}
         pages={pages}
         setPages={(newPages) => setPages(newPages)}
         setPlaceholder={(newPlaceholder) => setPlaceholder(newPlaceholder)}
         setSearchTerm={(newSearchTerm) => setSearchTerm(newSearchTerm)}
       />
+    )}
+  </>
 )}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd3fa94 and be442af.

📒 Files selected for processing (1)
  • web/core/components/command-palette/command-modal.tsx (1 hunks)
🔇 Additional comments (3)
web/core/components/command-palette/command-modal.tsx (3)

70-73: LGTM! Improved hook destructuring.

The addition of getIssueById from the useIssueDetail hook aligns with the PR's objective to use data from the mobx store.


91-92: LGTM! Fixed stale data issue.

The change to use getIssueById with the store data effectively resolves the mutation issue by ensuring the modal always displays the latest state.


84-89:

Details

❓ Verification inconclusive

Verify SWR cache configuration.

While the SWR call is correctly implemented, consider adding a revalidation strategy to ensure data consistency when the modal is reopened.


🌐 Web query:

What are the recommended SWR revalidation strategies for modals?

💡 Result:

When working with modals in applications using SWR, there are several recommended strategies to manage data revalidation effectively while maintaining optimal user experience:

Disabling Unwanted Automatic Revalidation

Modals often trigger focus events that cause unintended SWR revalidations. To prevent this:

  • Disable focus-based revalidation

    useSWR(key, fetcher, { 
      revalidateOnFocus: false 
    })

    This stops SWR from refetching data when the modal opens/closes or regains focus[1][4].

  • Full automatic revalidation disable
    For completely static modal content:

    useSWR(key, fetcher, {
      revalidateIfStale: false,
      revalidateOnFocus: false,
      revalidateOnReconnect: false
    })

    Or use the immutable helper:

    import useSWRImmutable from 'swr/immutable'
    useSWRImmutable(key, fetcher)

    This ensures data loads once and never refreshes[1][4].

Manual Revalidation Control

When you need explicit refresh control:

const { data, mutate } = useSWR('/api/data', fetcher)

// In modal close handler:
const handleClose = () => {
  mutate() // Trigger manual validation
}

This pattern works well for forms/modals needing post-submission updates[7].

Deduplication Strategies

For modals that might open/close rapidly:

useSWR(key, fetcher, {
  dedupingInterval: 5000 // Extend dedupe window
})

Prevents duplicate requests during quick modal interactions while maintaining fresh data[5].

Optimistic Updates Pattern

For modals handling mutations:

const handleSubmit = async (formData) => {
  try {
    await mutate(key, updateAPI(formData), {
      optimisticData: formData,
      rollbackOnError: true
    })
  } catch (error) {
    // Handle errors
  }
}

This provides instant UI feedback while safely handling server updates[3][7].

The key considerations are balancing stale data usage versus freshness requirements specific to your modal's purpose. For critical real-time data pair manual mutate() calls with conservative automatic refresh settings[1][6].

Citations:


SWR Revalidation Suggestion: Fine-Tune Your Modal’s Data Fetching Strategy

The current SWR hook is implemented correctly, but to avoid unintended revalidation when the modal reopens, consider adding a revalidation configuration. For example, you might add a third parameter to disable focus-based revalidation:

const { data: workItemDetailsSWR } = useSWR(
  workspaceSlug && workItem ? `ISSUE_DETAIL_${workspaceSlug}_${projectIdentifier}_${sequence_id}` : null,
  workspaceSlug && workItem
    ? () => fetchIssueWithIdentifier(workspaceSlug.toString(), projectIdentifier, sequence_id)
    : null,
  { revalidateOnFocus: false } // Prevents automatic revalidation when the modal regains focus
);

Alternatively, if your use case demands fresh data when the modal is reopened, you can control refresh behavior manually—calling the mutate() function after the modal closes to trigger a revalidation only when needed.

@sriramveeraghanta sriramveeraghanta merged commit 602ae01 into preview Feb 19, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-command-modal-mutation branch February 19, 2025 09:14
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* fix: command modal mutation

* chore: minor update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants